package com.example.computer_exam_training_sys.mapper;

import com.example.computer_exam_training_sys.entity.UserPracticeDetail;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface UserPracticeDetailMapper {

    @Select("SELECT * FROM user_practice_details")
    List<UserPracticeDetail> getAllPracticeDetails();

    @Select("SELECT * FROM user_practice_details WHERE practice_id = #{practiceId}")
    List<UserPracticeDetail> selectByPracticeId(@Param("practiceId") Integer practiceId);  // ← 统一命名

    @Insert("INSERT INTO user_practice_details (practice_id, question_id, is_correct, user_answer) " +
            "VALUES (#{practiceId}, #{questionId}, #{isCorrect}, #{userAnswer})")
    @Options(useGeneratedKeys = true, keyProperty = "detailId")
    int insertPracticeDetail(UserPracticeDetail detail);
    @Select("SELECT COUNT(*) FROM user_practice_details WHERE practice_id = #{practiceId} AND is_correct = 1")
    int countCorrectByPracticeId(@Param("practiceId") Integer practiceId);

    @Select("SELECT COUNT(*) FROM user_practice_details WHERE practice_id = #{practiceId}")
    int countTotalByPracticeId(@Param("practiceId") Integer practiceId);
}